class Solution:
    """会超时"""
    def countRangeSum(self, nums: list, lower: int, upper: int) -> int:
        if not nums:
            return 0
        res, length = int(lower <= nums[0] <= upper), len(nums)
        for index in range(1, length):
            nums[index] += nums[index - 1]
            res += (lower <= nums[index] <= upper)
        for i in range(length):
            for j in range(i+1, length):
                res += (lower <= nums[j] - nums[i] <= upper)
        return res


a = Solution()
print(a.countRangeSum(nums=[-2, 5, -1], lower=-2, upper=2))
